package o;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.os.Build;
import com.huawei.cloudservice.CloudAccountManager;
import com.huawei.fastengine.fastview.startFastappEngine.bean.RpkInfo;
import com.huawei.hms.framework.common.ContainerUtils;
import com.huawei.hwid.core.constants.HwAccountConstants;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.lang.Thread.UncaughtExceptionHandler;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.Date;

public class dos implements UncaughtExceptionHandler {
    private Context ˋ;
    private UncaughtExceptionHandler ˏ;
    private StringBuilder ॱ = new StringBuilder(4096);

    public synchronized void ˋ(Context context) {
        this.ˋ = context;
        this.ˏ = Thread.getDefaultUncaughtExceptionHandler();
        Thread.setDefaultUncaughtExceptionHandler(this);
    }

    public synchronized void uncaughtException(Thread thread, Throwable th) {
        if (this.ˏ != null) {
            if (ˎ(th)) {
                ˎ(this.ˋ, th);
            }
            this.ˏ.uncaughtException(thread, th);
        }
    }

    private boolean ˎ(Throwable th) {
        if (th == null || this.ˋ == null) {
            return false;
        }
        ॱ(this.ˋ);
        ˊ(th);
        return true;
    }

    public void ˎ(Context context, Throwable th) {
    }

    @SuppressLint({"SimpleDateFormat"})
    private void ॱ(Context context) {
        try {
            PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 1);
            this.ॱ.append("packageName").append(ContainerUtils.KEY_VALUE_DELIMITER).append(context.getPackageName()).append("\n");
            if (packageInfo != null) {
                String str = packageInfo.versionName == null ? HwAccountConstants.NULL : packageInfo.versionName;
                String str2 = packageInfo.versionCode + "";
                this.ॱ.append(CloudAccountManager.KEY_VERSION_NAME).append(ContainerUtils.KEY_VALUE_DELIMITER).append(str).append("\n");
                this.ॱ.append(RpkInfo.VERSIONCODE).append(ContainerUtils.KEY_VALUE_DELIMITER).append(str2).append("\n");
            }
        } catch (Throwable e) {
            Logger.ˋ("CrashHandler", "an error occured when collect package info", e);
        }
        for (Field field : Build.class.getDeclaredFields()) {
            try {
                field.setAccessible(true);
                if (!field.getName().equalsIgnoreCase("SERIAL")) {
                    this.ॱ.append(field.getName()).append(ContainerUtils.KEY_VALUE_DELIMITER).append(field.get(null).toString()).append("\n");
                }
            } catch (SecurityException e2) {
                Logger.ˋ("CrashHandler", "an error occured when collect crash info: SecurityException");
            } catch (IllegalArgumentException e3) {
                Logger.ˋ("CrashHandler", "an error occured when collect crash info: " + e3.toString());
            } catch (IllegalAccessException e4) {
                Logger.ˋ("CrashHandler", "an error occured when collect crash info: " + e4.toString());
            }
        }
        this.ॱ.append("time").append(ContainerUtils.KEY_VALUE_DELIMITER).append(new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss SS").format(new Date(System.currentTimeMillis()))).append("\n");
        this.ॱ.append("BuildConfig").append(ContainerUtils.KEY_VALUE_DELIMITER).append(String.valueOf(false)).append("\n");
    }

    private void ˊ(Throwable th) {
        Writer stringWriter = new StringWriter();
        PrintWriter printWriter = new PrintWriter(stringWriter);
        try {
            th.printStackTrace(printWriter);
            for (Throwable cause = th.getCause(); cause != null; cause = cause.getCause()) {
                cause.printStackTrace(printWriter);
            }
            this.ॱ.append("StackTrace").append(ContainerUtils.KEY_VALUE_DELIMITER).append(stringWriter.toString()).append("\n");
        } finally {
            printWriter.close();
        }
    }

    public String toString() {
        return this.ॱ.toString();
    }
}
